import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

//自定义组件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // MaterialApp是根组件
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('StatefulWidget'),
        ),
        body: HomePage(),
      ),
      theme: ThemeData(primaryColor: Colors.blue),
    );
  }
}

class HomePage extends StatefulWidget {
  HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int counter = 0;
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Chip(label: Text('${this.counter}')),
        ElevatedButton(
            onPressed: () {
              //setState用来改变组件状态
              setState(() {
                this.counter++;
              });
            },
            child: Text('button'))
      ],
    );
  }
}
